package cn.kailangtu.dataspot.services;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import androidx.annotation.Nullable;

import cn.kailangtu.dataspot.AppBasicMethod;

/**
 * Created by fujf on 2022/2/12
 * Description:
 */
public class KillSelfService extends Service {
    /**
     * 关闭应用后多久从新启动
     */
    private static long stopDelayed = 500;
    private Handler handler;
    private String PackageName;

    public KillSelfService() {
        handler = new Handler();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        stopDelayed = intent.getLongExtra("Delayed", 500);
        PackageName = intent.getStringExtra("PackageName");
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                AppBasicMethod.getInstance().startApp();
                KillSelfService.this.stopSelf();
            }
        },stopDelayed);

        return super.onStartCommand(intent, flags, startId);
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }


}